import current from '../core/current';
import logger from '../core/logger';
import getFavouriteBoxsVideoModel from '../model/other/getFavouriteBoxsVideoModel';
import getUserFovBox from '../model/other/getUserFovBox';
import returnModel from '../model/common/returnModel';
import apiInfo from './core/apiInfo';
import { clientBase } from './core/clientBase';

export class collectionClient extends clientBase {
  constructor() {
    super();
  }

  getFavType(): Promise<returnModel<getUserFovBox>> {
    var self = this;
    return new Promise((resolve) => {
      try {
        let info = new apiInfo("https://api.bilibili.com/medialist/gateway/base/created", `&channel=bilih5&pn=1&ps=20&type=2&up_mid=${current.instance.mid}`, null, true);
        this.client.getResult(info).then((res) => {
          var data: getUserFovBox = res;
          resolve(self.buildSuccessResult<getUserFovBox>(data));
        });
      } catch (e) {
        logger.error(e);
        resolve(this.buildExceptionResult<any>(e));
      }
    });
  }

  getVideoFavBox(fid: number, pageNum: number): Promise<returnModel<getFavouriteBoxsVideoModel>> {
    var self = this;
    return new Promise((resolve) => {
      try {
        let info = new apiInfo("http://api.bilibili.com/x/v2/fav/video", `&pn=${pageNum}&ps=20&tid=0&fid=${fid}&vmid=${current.instance.mid}&order=ftime`, null, true);
        this.client.getResult(info).then((res) => {
          var data: getFavouriteBoxsVideoModel = res;
          resolve(self.buildSuccessResult<getFavouriteBoxsVideoModel>(data));
        });
      } catch (e) {
        logger.error(e);
        resolve(this.buildExceptionResult<getFavouriteBoxsVideoModel>(e));
      }
    });
  }
}

export default new collectionClient();